package ru.jkff.jalgebra.monoid;

/**
 * User: jkff
 * Date: Aug 23, 2009
 * Time: 12:47:01 PM
 */
public abstract class AggregateUtils {
    private AggregateUtils() {}

    public static <T, A> A collect(Aggregate<T, A> aggregate, Iterable<T> ts) {
        A res = aggregate.freshUnit();
        collectInto(aggregate, ts, res);
        return res;
    }

    public static <T, A> void collectInto(Aggregate<T, A> aggregate, Iterable<T> ts, A dest) {
        for(T t : ts) aggregate.pushInto(t, dest);
    }
}
